import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Layouts 1.0


Rectangle {
    id: cusWindow_w_Root
    color: "transparent"
    radius: windowRadius
    signal close()

    property string title
    property bool needCloseBtn: true
    property int titleHeight: 50
    property int windowRadius: 20
    property bool titleLeftAlign: false
    property int leftTitleFontSize: Theme.font_size_15
    property int centerTitleFontSize: Theme.font_size_15

    Rectangle {
        id: titleBar
        anchors.top: cusWindow_w_Root.top
        anchors.left: cusWindow_w_Root.left
        anchors.right: cusWindow_w_Root.right
        implicitHeight: titleHeight
        color: Theme.second_window_title_color
        radius: windowRadius

        Rectangle {
            anchors.bottom: titleBar.bottom
            anchors.left: titleBar.left
            anchors.right: titleBar.right
            implicitHeight: titleBar.height / 2
            color: Theme.second_window_title_color
        }

        CusText {
            id: leftTitle
            text: title
            font.pixelSize: leftTitleFontSize
            font.weight: Font.Black
            color: "white"
            anchors.left: titleBar.left
            anchors.verticalCenter: titleBar.verticalCenter
            anchors.leftMargin: 10
            visible: titleLeftAlign
        }

        CusText {
            id: centerTitle
            text: title
            font.pixelSize: centerTitleFontSize
            font.weight: Font.Black
            color: "white"
            anchors.centerIn: titleBar
            visible: !titleLeftAlign
        }

        CusCloseBtn {
            id: closeBtn
            visible: needCloseBtn
            implicitHeight: titleHeight
            implicitWidth: titleHeight
            anchors.right: titleBar.right
            anchors.verticalCenter: titleBar.verticalCenter
            radius: windowRadius
            source_image_normal: "qrc:/image/window_close.svg"
            source_image_hovered: "qrc:/image/window_close.svg"
        }
    }

    Rectangle {
        id: contentBg
        anchors.top: titleBar.bottom
        anchors.left: cusWindow_w_Root.left
        anchors.right: cusWindow_w_Root.right
        anchors.bottom: cusWindow_w_Root.bottom
        radius: cusWindow_w_Root.radius

        Rectangle {
            anchors.top: contentBg.top
            anchors.left: contentBg.left
            anchors.right: contentBg.right
            implicitHeight: contentBg.height / 2
        }

        MouseArea { anchors.fill: parent; onClicked: { focus = true } }
    }
}
